package com.itheima.controller.order;

import com.itheima.entity.Checkgroup;
import com.itheima.message.BussinessSuccessMsg;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.QueryPageBean;
import com.itheima.pojo.Result;
import com.itheima.service.CheckgroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "检查组管理")
@RestController
@RequestMapping("/checkgroup")
public class CheckgroupController {

    @DubboReference
    private CheckgroupService checkgroupService;

    @ApiOperation("新增检查组")
    @PostMapping
    public Result add(@RequestBody Checkgroup Checkgroup, @ApiParam Integer[] checkitemIds) {
        checkgroupService.add(Checkgroup, checkitemIds);
        return Result.success(BussinessSuccessMsg.ADD_CHECKGROUP_SUCCESS);
    }

    @ApiOperation("删除检查组")
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id) {
        checkgroupService.deleteById(id);
        return Result.success(BussinessSuccessMsg.DELETE_CHECKGROUP_SUCCESS);
    }

    @ApiOperation("更新检查组")
    @PutMapping
    public Result update(@RequestBody @Validated Checkgroup Checkgroup, Integer[] checkitemIds) {
        checkgroupService.update(Checkgroup, checkitemIds);
        return Result.success(BussinessSuccessMsg.EDIT_CHECKGROUP_SUCCESS);
    }

    @ApiOperation("检查组详情")
    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id) {
        Checkgroup Checkgroup = checkgroupService.findOne(id);
        return Result.success(Checkgroup);
    }

    @ApiOperation("检查组分页查询")
    @PostMapping("/page")
    public Result selectPage(@RequestBody QueryPageBean queryPageBean) {
        PageResult<Checkgroup> data = checkgroupService.selectPage(queryPageBean);
        return Result.success(data);
    }
}
